package com.learn.project2.service.admin.log;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.learn.project2.bean.MarketLog;
import com.learn.project2.bean.MarketLogExample;
import com.learn.project2.mapper.MarketLogMapper;
import com.learn.project2.model.vo.admin.log.LogListVO;
import com.learn.project2.utils.BaseParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @author zhizhuke
 * @date 2022-01-08 09-10
 * @version 1.0
 */
@Service
//@CacheConfig(cacheNames = {"marketLog"})
public class LogServiceImpl implements LogService {
    @Autowired
    MarketLogMapper logMapper;
    /**
     * @description:
     * @param:
     * @return:
     * @author zhizhuke
     * @date: 2022-01-08 11:07
     */
   // @Cacheable
    @Override
    public LogListVO list(BaseParam param, String name) {
        Integer limit = param.getLimit();
        Integer page = param.getPage();
        String sort = param.getSort();
        String order = param.getOrder();

        PageHelper.startPage(page,limit);

        MarketLogExample example = new MarketLogExample();
        example.setOrderByClause(sort+" "+order);
        if (name!=null){
            example.createCriteria().andAdminLike(name);
        }

        List<MarketLog> list = logMapper.selectByExample(example);

        PageInfo<MarketLog> pageInfo = new PageInfo<>(list);
        int pages = pageInfo.getPages();
        long total = pageInfo.getTotal();

        return new LogListVO(((int) total),pages,limit,page,list);

    }
}
